# -- coding: UTF-8 --
import sys
import unittest
sys.path.append('D:\\Program Files\\Mercurial\\library')
import vowei

class TestClass(unittest.TestCase):
    def test_post_comment(self):
        vw = vowei.vowei()

        comments = []
        comments.append({
            'PostId': 7,
            'PostType': 'Ticket',
            'Text': u'关闭任务#7',
            'User': 'yimin_shi@hotmail.com'
        })
        comments.append({
            'PostId': 8,
            'PostType': 'Ticket',
            'Text': u'关闭任务#8',
            'User': 'yimin_shi@hotmail.com'
        })
        
        vw.post_comments(comments, 'localhost', '/vowei/Comment/PostComments');
        
    def test_no_ids(self):
        vw = vowei.vowei()
        expect = []
        actual = vw.find_work_item_ids('fix 123')
        compare_sets(expect, actual)
            
    def test_find_unicode_ids(self):
        vw = vowei.vowei()
        expect = [12, 34, 56]
        actual = vw.find_work_item_ids(u'完成工作任务#12和bug #34还有风险#56')
        compare_sets(expect, actual)

    def test_find_single_id(self):
        vw = vowei.vowei()
        expect = [123]
        actual = vw.find_work_item_ids('fix #123')
        compare_sets(expect, actual)

    def test_find_multiple_ids(self):
        vw = vowei.vowei()
        expect = [123, 456]
        actual = vw.find_work_item_ids('fix #123, #456')
        compare_sets(expect, actual)

        actual = vw.find_work_item_ids('fix #123 #456')
        compare_sets(expect, actual)

def compare_sets(expect, actual):
    if ( len(expect) != len(actual) ):
        raise Exception('two set counts are different, expect: %d, actual: %d' % (len(expect), len(actual)))

    actual.difference_update(expect)
    if ( len(actual) != 0 ):
        raise Exception('two set have different items')

unittest.main()
